package cc.shimeng.fucloud.controller;

import cc.shimeng.fucloud.entity.Classes;
import cc.shimeng.fucloud.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/classes")
public class ClassesController {

    @Autowired
    private ClassesService classesService;

    @GetMapping
    public List<Classes> getAll() {
        return classesService.findAll();
    }

    @GetMapping("/{id}")
    public Classes get(@PathVariable Integer id) {
        return classesService.findById(id);
    }

    @PostMapping
    public Classes create(@RequestBody Classes classes) {
        return classesService.save(classes);
    }

    @PutMapping("/{id}")
    public Classes update(@PathVariable Integer id, @RequestBody Classes classes) {
        return classesService.save(classes);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        classesService.deleteById(id);
    }
}